function [RES,UCoef,SS]=SteadyState_Solver_Res(PP,SS,BellmanItSetup,Input,UCoef_0)

%% Initiation
if nargin<=3
    Input      =   [1.2;1.1];
end
PSI         =   Input(1);
DiscFactor  =   Input(2);
% PSI         =   1.2;
% FracHN_w    =   1.1;
% DiscFactor  =   0.2;

SS.ExitFlag =   0;
%% Preliminaries
SS.PSI      =   PSI;
SS.BETA     =   1/(1+DiscFactor);

%--------------------------------------------------------------------------
% Directly Determined by the Steady State Target
%   Note:
%       1. 
%--------------------------------------------------------------------------
% Step 1. Solve mc_p
SS.mc_p     =   ( PP.EPSILON-1 )/PP.EPSILON;
% Step 2. Solve w
SS.w        =   SS.wN/SS.N;
% Step 3. Solve pY
SS.pY       =   SS.w*SS.N/(1-PP.ALPHA)/SS.mc_p;
% Step 4. Solve Y, PAC, Profit
SS.PAC      =   0;
SS.Profit   =   SS.pY-SS.PAC-SS.w*SS.N;
SS.Y        =   SS.pY;
% Step 5. Solve B and G
% SS.B        =   SS.Y*PP.B_Y_SS;
% SS.G        =   SS.B/(1+SS.ir)+SS.TAU-SS.B/(1+SS.Pir)-SS.T;

% SS.G        =   0;
% SS.B        =   (SS.G+SS.T-SS.TAU)*(1+SS.ir)*(1+SS.Pir)/(SS.Pir-SS.ir);

% SS.G        =   0;
% SS.B        =   0;
% SS.T        =   SS.TAU-SS.G-SS.B*(SS.ir-SS.Pir)/( (1+SS.Pir)*(1+SS.ir) );

if SS.T+(SS.ir+PP.KAPPA)*PP.b_lb<0
    warning('Transfer is too small to cover the unemployed consumption.');
end

%% Solve the Bellman Equation
% Setup the Approximation Structure

% Initialization
if nargin<=4 || (nargin==5 && isempty(UCoef_0))
    Uhat_0      =   Fun_Vhat(PP,SS,SS.T,SS.Profit,SS.TAU,SS.w,SS.FunApp.U.State);
    UCoef_0     =   SS.FunApp.U.BasMat_0_State\Uhat_0;
end
% Solve Value Function
% BellmanItSetup=   struct('ValItNum',0,'ColItNum',1,'TolItNum',5000,...
%                          'PrintFlag',2,'DampenCoef',1);
ValItNum    =   BellmanItSetup.ValItNum;
ColItNum    =   BellmanItSetup.ColItNum;
TolItNum    =   BellmanItSetup.TolItNum;
PrintFlag   =   BellmanItSetup.PrintFlag>=2;
DampenCoef  =   BellmanItSetup.DampenCoef;
[UCoef,Info,ExitFlag] ...
            =   SteadyState_Bellman(PP,SS,UCoef_0,...
                                    ValItNum,ColItNum,TolItNum,...
                                    PrintFlag,DampenCoef);
if ExitFlag==1
    SS.UCoef        =   UCoef;
    SS.VbarCoef     =   Info.FunCoef.Vbar;
    SS.BellmanInfo  =   Info;
    SS.ExitFlag     =   1;
else
    fprintf('Bellman Solver does not Converge!\n');
    return;
end
%% Solve the Policy
SS.Policy   =   Policy_Solver(PP,SS,SS.T,SS.Profit,SS.TAU,SS.ir,SS.w,...
                              SS.UCoef,SS.PolApp.V.State);
                          
%% Solve the Distribution
% SS.SimuSample=  SteadyState_Distribution_Simulation(PP,SS,5000,100);
% SS.DistApp  =   SteadyState_DistApp(PP,SS);
% Solve the Policy over the Distribution Grid
SS.DistPolicy=  Policy_Solver(PP,SS,SS.T,SS.Profit,SS.TAU,SS.ir,SS.w,...
                              SS.UCoef,SS.DistApp.fz.State);

% Solve the Approximated Distribution
[SS.TrProb.FlowVec,SS.TrProb.CoefMat,SS.TrProb.UnitTrMat] ...
            =   Distribution_TrProbMat(PP,SS,SS.Pir,SS.DistPolicy);
SS.Dist_fz  =   SteadyState_Distribution(PP,SS);

%% Aggregation
SS.Agg      =   Aggregation(PP,SS,SS.Dist_fz.QW_fz,SS.DistPolicy,SS.TrProb.UnitTrMat);

SS.B        =   SS.Agg.B;

SS.C        =   SS.Agg.C;

SS.L        =   SS.Agg.L;

SS.FC_Agg   =   SS.Agg.FC;
SS.UI_Agg   =   SS.Agg.UI;


%% Residuals
RES_B       =   SS.B-PP.B_Total_SS;
RES_L       =   SS.N-SS.L;
RES_C       =   SS.C-SS.Y;

RES         =   [RES_B;RES_L];
% RES         =   [RES_B;RES_L;RES_FracHN_L];

RES_FinalGood=  (SS.Agg.Tot.f.poor+SS.Agg.Tot.f.rich) ...
                +SS.T+SS.Profit+SS.UI_Agg+(1-SS.TAU)*SS.wN ...
                -SS.C-(SS.B+SS.FC_Agg)/(1+SS.ir);

SS.RES      =   RES;
SS.RES_FinalGood ...
            =   RES_FinalGood;

%% Solve the Derived Quantities and Prices
% Prices
% SS.p_T      =   (SS.FracTN_pC/(1+SS.FracTN_pC)*1/PP.Cons_FracT)^(1/(1-PP.Cons_ElasTN));
% SS.p_N      =   (1/(1+SS.FracTN_pC)*1/(1-PP.Cons_FracT))^(1/(1-PP.Cons_ElasTN));
% SS.p_H      =   (SS.FracHF_pC/(1+SS.FracTN_pC)*1/PP.Cons_FracH)^(1/(1-PP.Cons_ElasHF))*SS.p_T;
% SS.p_F      =   (1/(1+SS.FracTN_pC)*1/(1-PP.Cons_FracH))^(1/(1-PP.Cons_ElasHF))*SS.p_T;
% Consumption Basket
SS.p        =   1;
% Production
SS.mc       =   SS.mc_p*SS.p;
SS.Z        =   SS.Y/SS.N^(1-PP.ALPHA);
% Government
SS.G        =   SS.B/(1+SS.ir)+SS.TAU-SS.B/(1+SS.Pir)-SS.T;